package com.ruoyi.web.controller.app;

import com.ruoyi.business.domain.TFeedback;
import com.ruoyi.business.domain.TJoinApply;
import com.ruoyi.business.service.ITFeedbackService;
import com.ruoyi.business.service.ITJoinApplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * App端 运营与其他接口
 *
 * @author laoguo
 */
@RestController
@RequestMapping("/app")
public class AppOperationController extends BaseController {

    @Autowired
    private ITFeedbackService feedbackService;

    @Autowired
    private ITJoinApplyService joinApplyService;

    /**
     * 提交意见反馈
     */
    @PostMapping("/feedback/submit")
    public AjaxResult submitFeedback(@Validated @RequestBody TFeedback feedback) {
        LoginUser loginUser = SecurityUtils.getLoginUser();

        feedback.setUserId(loginUser.getUserId());
        feedback.setUserNickname(loginUser.getUsername());
        feedback.setCreateBy(loginUser.getUsername());

        return toAjax(feedbackService.insertTFeedback(feedback));
    }

    /**
     * 提交加盟信息
     */
    @PostMapping("/join/submit")
    public AjaxResult submitJoinApply(@Validated @RequestBody TJoinApply joinApply) {
        // 尝试获取登录用户ID，如果未登录则为null
        try {
            joinApply.setUserId(SecurityUtils.getUserId());
        } catch (Exception e) {
            // 用户未登录，忽略异常
        }

        return toAjax(joinApplyService.insertTJoinApply(joinApply));
    }
}